package com.cenntro.oss.controller;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


import com.cenntro.common.util.result.Result;
import com.cenntro.oss.mapper.SysAgentMapper;
import com.cenntro.oss.model.dbo.SysAgentDO;
import com.cenntro.oss.service.SysSooidService;

/**
 * <p>
 * 账号数据表 前端控制器
 * </p>
 *
 * @author 
 * @since 2019-03-21
 */
@RestController
@RequestMapping("/sooid")
public class SysSooidController {
	
	@Resource
	private SysSooidService sysSooidService;
	
	@Resource
	private SysAgentMapper sysAgentMapper;
	/**
	 * 修改密码
	 * @param userName
	 * @param newPassword
	 * @return
	 */
	@RequestMapping("/updatePassword")
	@CrossOrigin
	public Result updatePassword(String userName,String newPassword){
		if (StringUtils.isNoneBlank(userName,newPassword)) {
			Integer updatePassword = sysSooidService.updateNewPassword(newPassword,userName);
			if (updatePassword==1) {
				return Result.ok();
			}else{
				return Result.error("失败");
			}
		} else {
			return Result.error("参数错误");
		}
	}
	
	/**
	 * 修改头像
	 * 
	 * @param agentId
	 * @return
	 */
	@RequestMapping("/updateHeadPic")
	@CrossOrigin
	public Result updateHeadPic(String userName, HttpServletRequest request) {
		if (StringUtils.isNotBlank(userName)) {
			return sysSooidService.updateHeadPic(userName, request);
		} else {
			return Result.error("参数错误");
		}
	}
	
	/**
	 * 修改联系人
	 * @param agentId
	 * @param linkMan
	 * @return
	 */
	@RequestMapping("/updateLinkName")
	@CrossOrigin
	public Result updateLinkName(Integer agentId,String linkMan){
		SysAgentDO agentDO = new SysAgentDO();
		agentDO.setLinkMan(linkMan);
		agentDO.setId(agentId);
		sysAgentMapper.update(agentDO);
		return Result.ok();
		
	}

}
